<template>
  <div class="upadta-sex">
    <van-picker
      title="标题"
      show-toolbar
      :columns="columns"
      @confirm="onConfirm"
      @cancel="onCancel"
      :default-index="+value"
    />
  </div>
</template>

<script>
import store from "@/store";
import { reRefrash_token } from "@/utils/setToken";
import { mapMutations } from "vuex";
import { updataUsername } from "@/api/user";

export default {
  name: "UpdataSex",
  components: {},
  props: {
    value: {
      type: [String],
    },
  },
  data() {
    return {
      columns: ["男", "女"],
    };
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {},
  methods: {
    ...mapMutations("user", ["setToken"]),
    async onConfirm(value, index) {
      console.log(`当前索引：${index}`);
      this.$emit("input", index + "");
      await updataUsername(
        store.getters.id,
        reRefrash_token({ user_sex: index + "" })
      );
      this.$toast.success("修改成功");
      this.setToken(reRefrash_token({ user_sex: index + "" }));
      this.$emit("close");
    },
    onCancel() {
      this.$emit("close");
    },
  },
};
</script>
<style lang='less' scoped>
</style>
